<jsp:include page="logincheck.jsp" />
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>

<jsp:useBean id="bill" class="se2.Bill" scope="request"/>
<jsp:setProperty name="bill" property="*"/>

<html>

	<head>
		<title>Administration Console</title>
		<link rel="stylesheet" href="default.css" type="text/css" media="screen"></link>
		<script src="sorttable.js"></script>
	</head>

	<body>
		<div id="container">
			<div id="navigation">
<p>&nbsp;</p>
<jsp:include page="navigation.jsp" />
			</div>
			
			<div id="header">				
				<img src="images/header.png" />
			</div>

			<div id="content">
<!-- Main code -->
				
				<!-- Initialize the Bill Object -->
				<% 
					boolean odd = false;
					bill.generateBillById(Integer.parseInt(request.getParameter("bid")));
					
					DecimalFormat dcf = new DecimalFormat("#0.00");
					dcf.setDecimalSeparatorAlwaysShown(true);
				%>
				
				<h1>Phone Bill :: View</h1>
	
				<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
								
					<tr style="background-image: url('images/tableBackground.png');">
						<th style="background-image: url('images/tableBackground.png');" width="*" class="sorttable_nosort tableHeader">&nbsp;</th>
						<th style="background-image: url('images/tableBackground.png');" width="*" class="tableHeader" align="left">Time</th>
						<th style="background-image: url('images/tableBackground.png');" width="*" class="tableHeader" align="center">Extension Dialed</th>
						<th style="background-image: url('images/tableBackground.png');" width="*" class="tableHeader" align="center">Duration (mins)</th>
						<th style="background-image: url('images/tableBackground.png');" width="*" class="tableHeader" align="center">Amount</th>
						<th style="background-image: url('images/tableBackground.png');" width="*" class="sorttable_nosort tableHeader">&nbsp;</th>
					</tr>

					<c:forEach var="callRecord" items="${bill.callRecords}">
						<% if (odd) { %>
							<tr style="background-image: url('images/tableBackground.png');">
						<% } else { %>
							<tr>
						<% } odd = !odd; %>
							<td>&nbsp;</td>
							<td sorttable_customkey="${callRecord.sortStartTime}">${callRecord.formattedStartTime}</td>
							<td align="center">${callRecord.toExtension}</td>
							<td align="center">${callRecord.duration}</td>
							<td align="right">${callRecord.formattedAmount}</td>
							<td>&nbsp;</td>
						</tr>
					</c:forEach>
					<tfoot>
					<tr><td>Bill Total</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td align="right">$<%= dcf.format(bill.getTotal()) %></td></tr>
					<tr><td>Existing Balance</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td align="right">$<%= dcf.format(bill.getBalance()) %></td></tr>
					<tr><td>Final Total</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td align="right">$<%= dcf.format(bill.getBalance() + bill.getTotal()) %></td></tr>
					<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td align="right"><input type="button" value="Cancel" onclick="javascript:document.location.href='viewBill.jsp?id=<%= request.getParameter("id") %>&cid=<%= request.getParameter("cid") %>'" /></td>
					</tfoot>
				</table>


<!-- Main Code -->
			</div>

			<div id="footer">
<jsp:include page="footer.jsp" />
			</div>
		</div>
	</body>

</html>